import { useCallback } from "react";
import { useDispatch, useSelector } from "react-redux";
import Creator from "../store/actions";
// 引入api
import CommsApi from "../api/comms";
import LabelsApi from "../api/labels";


export const useOneComm = () => {
    // 获取全部父类型数据
    const comm = useSelector(state => {
        return state.comm
    })
    const dispatch = useDispatch();
    // 操作状态的行为

    // _id对应的商品信息
    const getOneComm = useCallback(async (_id) => {
        const data = await CommsApi.getOne({_id})
        const {childId}=data
        const {parentId,title} = await LabelsApi.getOne({_id:childId})
        dispatch(Creator.getOneComm({data,parentId,title}));
    }, [dispatch]);

    return [comm, { getOneComm}]

}